package com.hotec.PROJECT_NAME.modules.sys.controller;

import com.hotec.PROJECT_NAME.component.basic.BaseController;
import com.hotec.PROJECT_NAME.component.basic.JsonContent;
import com.hotec.PROJECT_NAME.component.enums.SmsEnum;
import com.hotec.PROJECT_NAME.modules.sys.service.AbstractSmsService;
import com.hotec.PROJECT_NAME.utils.UtilsSms;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("sms")
public class SmsController extends BaseController {
    @Resource(name = "${sys.type}SmsService")
    private AbstractSmsService smsService;

    @PostMapping("/login/trust")
    public JsonContent sendTrustLoginCode (@RequestParam String mobile, @RequestParam String imgCode){
        smsService.send(mobile, imgCode, SmsEnum.LOGIN, "trustLogin");

        return this.success();
    }

    @PostMapping("/login/shop")
    public JsonContent sendShopLoginCode (@RequestParam String mobile, @RequestParam String imgCode){
        smsService.send(mobile, imgCode, SmsEnum.LOGIN, "shopLogin");

        return this.success();
    }

    @PostMapping("/registry/shop")
    public JsonContent sendShopRegistryCode (@RequestParam String mobile, @RequestParam String imgCode){
        smsService.send(mobile, imgCode, SmsEnum.REGISTER, "shopRegistry");

        return this.success();
    }

    @GetMapping("/validCode/{type}/{mobile}")
    public void getValidCodeByType (@PathVariable String type, @PathVariable String mobile, HttpServletResponse response){
        UtilsSms.getImgCode(type, mobile, response);
    }
}
